<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/14
 * Time: 14:41
 * 结账步骤一
 */
require('env.php');
require('init.inc.php');
include_once 'functions.php';
if (isset($_GET['OrderProdDBId'])) {
    $OrderProdDBId = $_GET['OrderProdDBId'];
} else {
    $OrderProdDBId = '';
}


$tongji1 = home_tongji(1);
$tongji2 = home_tongji(2);
$tongji3 = home_tongji(3);
$index_std = ShopConfig::getConfig();
?>

<!DOCTYPE html>
<html>
<?php include("header.php"); ?>
<style>
    .form-group1 {
        background-color: white;
        width: 100%;
    }

    .modal-title_n {
        width: 100%;
        font-size: 20px;
    }

    .modal-ele {
        margin-left: 20%;
        font-size: 15px;
        font-weight: bold;
        line-height: 40px;
    }

    .modal-elet {
        font-size: 15px;
        color: blue;
    }

    .modal-xiao {
        font-size: 18px;
        background-color: whitesmoke;
    }

    .btn-item {
        height: 50px;
        background: #FF6F20 url(style/images/btn-totop.png) 18px 18px no-repeat;
        background-size: 15px;
        bottom: 700px;
        position: fixed;
        width: 100%;
    }

    .btn-item a {
        height: 50px;
        line-height: 50px;
        display: block;
        border-left: 1px solid #FFF;
        text-align: center;
        font-size: 16px;
        color: #FFF;
        margin: 0 0 0 50px;
        font-weight: bold;
    }

    .btn_a {
        font-size: 18px;
    }

    .modal-f {
        margin-left: 16%;
        padding: 15px;
        border-top: 1px solid #e5e5e5;

    }

    .nex {
        background-color: blueviolet;
        color: white;
        width: 32%;
    }
</style>
<body>
<div class="form-group1" id="order_span">
    <div class="modal-header">
        <h4 class="modal-title_n">只要三步 -- <span style="color: blue;">1</span> / 3</h4>
    </div>


    <div class="modal-ele">
        <span>運送方式： <input type="checkbox" checked disabled value="100" id="ysfs"/><span class="modal-xiao">宅配到家</span></span>
    </div>
    <div class="modal-ele">
        <span>付款方式：<input type="radio" name="fkfs" checked disabled value="112" id="fkfs"/><span class="modal-xiao">在线支付</span></span>
    </div>

    <div class="modal-f">
        <span class="btn_a"> <input type="button" value="查看購物清單" onclick="gocart()"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
                class="nex" type="button" value="下一步" onclick="next_stp2()"/></span>
    </div>
</div>
<div style="display:none;">
    <?php echo str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji1['tongji'], ENT_QUOTES)) . '<br/>' . str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji2['tongji'], ENT_QUOTES)) . '<br/>' . str_replace("&nbsp;", ' ', htmlspecialchars_decode($tongji3['tongji'], ENT_QUOTES)) . '<br/>'; ?>
</div>

<script type="text/javascript">
    function gocart() {
        //判定下目前有沒有物品購物車裏面
        $.ajax({
            url: 'order.php',// 跳转到 action
            data: {
                isUpdate: -1
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.msg == "true") {
                    window.location.href = '<?php echo SERVER_ROOT?>' + 'shop_cart.php?OrderProdDBId=' + '<?php echo $OrderProdDBId?>';
                } else {
                    alert("當前購物車為空，請先選購商品");
                    window.location.href = '<?php echo SERVER_ROOT?>' + 'index.php';
                }
            },
            error: function () {
                alert("服務器錯誤！");
            }
        });
    }


    function next_stp2() {
        //提交通過了就直接可以跳轉到下一步
        var ysfs = $("#ysfs").val();
        var fkfs;

        $("input[name='fkfs']").each(function () {
            if ($(this).get(0).checked) {
                fkfs = $(this).val();
            }
        });

        if (!fkfs) {
            alert("必須選一種付款方式");
            return;
        }
        //数据库id
        $.ajax({
            url: 'order.php',// 跳转到 action
            data: {
                isUpdate: '0_add',
                ysfs: ysfs,
                fkfs: fkfs,

            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.msg == "true") {
                    window.location.href = '<?php echo SERVER_ROOT?>' + 'invoicing_stp2.php?oid=' + data.id + '&OrderProdDBId=' + '<?php echo $OrderProdDBId?>';
                } else {
                    alert(data.content);
                }
            },
            error: function () {
                alert("服務器錯誤！");
            }
        });
    }
</script>
</body>
</html>




